package com.mogist.hqc.module.common.presenter

import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.CommentListVo
import com.mogist.hqc.module.common.contract.CommentListContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool
import talex.zsw.basecore.view.dialog.sweetalertdialog.SweetAlertDialog

/**
 * 作用：评论列表
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class CommentListPresenter(view: CommentListContract.View) : _PresenterImpl<CommentListContract.View, BaseResponse>(
        view), CommentListContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.PRODUCT_COMMENT, Constant.TYPE_COMMENT_LIST ->
            {
                mView.disLoading()
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, CommentListVo::class.java)
                    mView.bindComment(vo)
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "获取评论列表失败", response.message)
                }
            }
            Constant.TYPE_COMMENT_ADD                            ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    mView.commentSuccess()
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "发表评论失败", response.message)
                }
            }
        }
    }

    override fun requestError(msg: String?, httpDto: HttpDto?)
    {
        mView.disLoading()
        super.requestError(msg, httpDto)
    }
}